<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>新增报价方案配置属性</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
	<form id="formSet1">
		<div class="fieldset1 tabel_col clearFix">
			<div class="fieldBox col_33">
				<div class="label">业务类型</div>
				<div class="field">
					<input type="text" id="bizTypCd" name="bizTypCd" ltype="combobox" placeholder="请选择"/>
					<input type="checkbox" id="bizTypCd_flag" name="bizTypCd_flag"/>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">项目类型</div>
				<div class="field">
					<input type="text" id="prjTypCd" name="prjTypCd" ltype="combobox" placeholder="请选择"/>
					<input type="checkbox" id="prjTypCd_flag" name="prjTypCd_flag"/>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">业务来源</div>
				<div class="field">
					<input type="text" id="bizResCd" name="bizResCd" ltype="combobox" placeholder="请选择"/>
					<input type="checkbox" id="bizResCd_flag" name="bizResCd_flag"/>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">组织架构</div>
				<div class="field">
					<input name="orgCd" id="orgCd" type="text" value="" placeholder="请选择" ltype="combobox">
					<input type="checkbox" id="orgCd_flag" name="orgCd_flag"/>
				</div>
			</div>
			<!-- <div class="fieldBox col_33">
				<div class="label">省</div>
				<div class="field">
					<input type="text" id="rgnPrCd" name="rgnPrCd" ltype="combobox" placeholder="请选择"/>
					<input type="checkbox" id="rgnPrCd_flag" name="rgnPrCd_flag" />
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">市</div>
				<div class="field">
					<input name="rgnCyCd" id="rgnCyCd" type="text" value="" placeholder="请选择" ltype="combobox">
					<input type="checkbox" id="rgnCyCd_flag" name="rgnCyCd_flag" />
				</div>
			</div> -->
			<div class="fieldBox col_33">
				<div class="label">经销商类型</div>
				<div class="field">
					<input type="text" id="splTypCd" name="splTypCd" ltype="combobox" placeholder="请选择"/>
					<input type="checkbox" id="splTypCd_flag" name="splTypCd_flag"/>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">是否团单</div>
				<div class="field">
					<%-- <select name="isGrpOrder" id="isGrpOrder" data-value=" ">
						<option value=" " checked >请选择</option>
						<c:forEach items="${yesOrNoCdList }" var="kv">
							<option value="${kv.key }">${kv.value }</option>
						</c:forEach>
					</select> --%>
					<input type="text" id="isGrpOrder" name="isGrpOrder" ltype="combobox" placeholder="请选择"/>
					<input type="checkbox" id="isGrpOrder_flag" name="isGrpOrder_flag"/>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">产品品牌</div>
				<div class="field">
					<input type="text" id="brCd" name="brCd" ltype="combobox" placeholder="请选择"/>
					<input type="checkbox" id="brCd_flag" name="brCd_flag"/>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">产品类型</div>
				<div class="field">
					<input name="prdTypCd" id="prdTypCd" type="text" value="" placeholder="请选择" ltype="combobox">
					<input type="checkbox" id="prdTypCd_flag" name="prdTypCd_flag"/>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">所属机构</div>
				<div class="field">
					<input name="friBaseOrgCd" id="friBaseOrgCd" type="text" value="" placeholder="请选择" ltype="combobox">
					<input type="checkbox" id="friBaseOrgCd_flag" name="friBaseOrgCd_flag"/>
				</div>
			</div>
			<div class="fieldBox col_100_auto">
				<div class="label">供应商</div>
				<div class="field">
					<input name="splIds" id="splIds" type="text" value="" placeholder="请选择" ltype="combobox">
					<input type="checkbox" id="splIds_flag" name="splIds_flag"/>
				</div>
			</div>
			<div class="fieldBox col_100_auto">
				<div class="label">产品型号</div>
				<div class="field">
					<input name="prdMdls" id="prdMdls" type="text" value="" placeholder="请选择" ltype="combobox">
					<input type="checkbox" id="prdMdls_flag" name="prdMdls_flag"/>
				</div>
			</div>
			<div class="fieldBox col_100">
				<div class="label">注意:</div>
				<div class="field">
					<span name="" id="" style="color: red;">参与方案配置的选项只需在对应项后面打上勾即可;省/市只可选其一作为方案配置条件</span>
				</div>
			</div>
		</div>
		<div class="btnsBox">
			<span id="saveBtn1" class="sq-button sq-button-round" onclick="add();">保存</span>
			<input name="prpsCfgId" id="prpsCfgId" type="hidden" value="${prpsCfgId }">
		</div>
	</form>
</div>

<script type="text/javascript">
var attrGrid;
$(function(){
	//业务类型
	var _businessTypCdListJOSN = ${businessTypCdListJOSN};
	$("#bizTypCd").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
        data: _businessTypCdListJOSN,
        valueField: 'key',
        textField:'value'
    });
	//项目类型
	var _prjTypCdListJSON = ${prjTypCdListJSON};
	$("#prjTypCd").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
        data: _prjTypCdListJSON,
        valueField: 'key',
        textField:'value'
    });
	//业务来源
	var _bizResCdListJSON = ${bizResCdListJSON};
	$("#bizResCd").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
        data: _bizResCdListJSON,
        valueField: 'key',
        textField:'value'
    });
	//经销商类型
	var _splTypCdListJSON = ${splTypCdListJSON};
	$("#splTypCd").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
        data: _splTypCdListJSON,
        valueField: 'key',
        textField:'value'
    });
	//是否团单
	var _yesOrNoCdListJSON = ${yesOrNoCdListJSON};
	$("#isGrpOrder").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
        data: _yesOrNoCdListJSON,
        valueField: 'key',
        textField:'value'
    });
	//产品品牌
	var _brCdListJSON = ${brCdListJSON};
	$("#brCd").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
        data: _brCdListJSON,
        valueField: 'key',
        textField:'value'
    });
	//业务来源
	var _regionProvinceListJSON = ${regionProvinceListJSON};
	$("#rgnPrCd").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
        data: _regionProvinceListJSON,
        valueField: 'key',
        textField:'value'
    });
	//所属机构
	var friBaseList = ${friBaseList};
	$("#friBaseOrgCd").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
		data: friBaseList,
		valueField: 'insCode',
		textField: 'fundRasInsNmShow'
	});

	//*****************省市下拉树******************************/
	$("#rgnCyCd").ligerComboBox({
            // width: 178,
            selectBoxWidth: 200,
            selectBoxHeight: 150,
            treeLeafOnly: true,  //限制只能选叶节点，父节点不能点击
            textField:"rgnNm",
            valueField:"rgnCd",
            tree: {
                url: '<%=path%>/project/prjQuatPrpsAttr/getRegionTreeData.do',
                ajaxType: 'get',
                checkbox: true,
                isExpand: false,
                parentIcon: "none",
                childIcon: "none",
                textFieldName:"rgnNm",
                idFieldName:"rgnCd",
                onSuccess: function () {
                    var treeselect=liger.get("rgnCyCd");
                    //treeselect.setValue("Q");
                }
            }
        });
	//*****************产品类型下拉树******************************/
	$("#prdTypCd").ligerComboBox({
            // width: 178,
            selectBoxWidth: 240,
            selectBoxHeight: 150,
            treeLeafOnly: true,  //限制只能选叶节点，父节点不能点击
            textField:"tName",
            valueField:"tCode",
            tree: {
                url: '<%=path%>/product/prdBscInfo/getPrdTyeDataForSearch.do',
                ajaxType: 'get',
                checkbox: true,
                parentIcon: "none",
                childIcon: "none",
                textFieldName:"tName",
                idFieldName:"tCode",
                isExpand:false,
                onSuccess: function () {
                    var treeselect=liger.get("prdTypCd");
                    //treeselect.setValue("Q");
                }
            }
        });
	//*****************组织架构下拉树******************************/
	$("#orgCd").ligerComboBox({
            // width: 178,
            selectBoxWidth: 240,
            selectBoxHeight: 150,
            treeLeafOnly: true,  //限制只能选叶节点，父节点不能点击
            textField:"orgNm",
            valueField:"orgCd",
            tree: {
                url: '<%=path%>/project/prjQuatPrpsAttr/getOrgCdDataForSearch.do',
                ajaxType: 'get',
                checkbox: true,
                parentIcon: "none",
                childIcon: "none",
                textFieldName:"orgNm",
                idFieldName:"orgCd",
	            isExpand:false,
                onSuccess: function () {
                    var treeselect=liger.get("orgCd");
                    //treeselect.setValue("Q");
                }
            }
        });

	//*****************供应商复选下拉框****************************/
	var comboGrid_defaultValue="${splIdsString}"; //初始值(value)
	var comboGrid_defaultText="${splIdsStringNm}"; //初始值(text)
	var isInit_setSearchComboVal = false; //是否初始化的时候已经赋完初始值？
	var combo_Mng = $("#splIds").ligerComboBox({
	    width: 400, 
	    selectBoxWidth: 380,
	    selectBoxHeight: 240,
	    valueField: 'id',
	    textField: 'splNm',
	    isMultiSelect: true,
	    grid: getGridOptions(true),
	    condition: {
	        labelWidth: 0,
	        space: 5,
	        fields: [{ name: 'splNm', width: 150, keyName: 'id'}]
	    },
	    delayLoadGrid: false,
	    onChangeValue: function (value) {
	        if (combo_Mng) {
	        	if (value=="") comboGrid_defaultValue = ""; //如果点击清空'x'，就滞空初始值
	        };
	        SetIframe_height();
	    }
	});
	function getGridOptions(checkbox)
	{
		var url; 
		if(comboGrid_defaultValue==""){
			url = '<%=path%>/product/splInfo/initList.do?flag=quote'
		}else{
			url = '<%=path%>/product/splInfo/initList.do?flag=quote&splIdString='+comboGrid_defaultValue;
		}
	    var options = {
	    	usePager: false,
	        columns: [
	            { display: '供应商', name: 'splNm', minWidth: 300 }
	        ],
	        switchPageSizeApplyComboBox: false,
	        url : url,
	        method: 'get',
	        dataAction: 'local',
	        pageSize: 10,
	        root:'rows',
	        record:'total',
	        usePagerOnLessPagesize: false,
	        cssClass: "SMALL_grid",
	        checkbox: checkbox,
	        frozen: false,
	        isSelected: function (rowdata) {
	            if (comboGrid_defaultValue == "") return false;
	            var defaultItems = comboGrid_defaultValue.split(";");
	            if(!isInit_setSearchComboVal) { //只在初始化时执行一次，在onAfterShowData后改变
	                for (var i = 0; i < defaultItems.length; i++) {
	                	if(rowdata[combo_Mng.options.valueField] == defaultItems[i]) return true;
	                }
	            }
	            return false;
	        },
	        onAfterShowData: function (currentData) {
	        	if(!isInit_setSearchComboVal) { //只在初始化时执行一次，在onAfterShowData后改变
	            	//combo_Mng.selectValue(comboGrid_defaultValue);
	            	combo_Mng.setInputValue(comboGrid_defaultValue, comboGrid_defaultText, true);
	                isInit_setSearchComboVal = true;
	        	}
	        	
	        }
	    };
	    return options;
	}
	//*****************产品选型号复选下拉框****************************/
	var comboGrid_defaultValue_prdMdl="${prdMdlsString}"; //初始值(value)
	var comboGrid_defaultText_prdMdl="${prdMdlsStringNm}"; //初始值(text)
	var isInit_setSearchComboVal_prdMdl = false; //是否初始化的时候已经赋完初始值？
	var combo_Mng_prdMdl = $("#prdMdls").ligerComboBox({
	    width: 400, 
	    selectBoxWidth: 380,
	    selectBoxHeight: 240,
	    valueField: 'prdMdl',
	    textField: 'prdMdl',
	    isMultiSelect: true,
	    grid: getGridOptions_prdMdl(true),
	    condition: {
	        labelWidth: 0,
	        space: 5,
	        fields: [{ name: 'prdMdl', width: 150, keyName: 'id'}]
	    },
	    delayLoadGrid: false,
	    onChangeValue: function (value) {
	        if (combo_Mng_prdMdl) {
	        	if (value=="") comboGrid_defaultValue_prdMdl = ""; //如果点击清空'x'，就滞空初始值
	        };
	        SetIframe_height();
	    }
	});
	function getGridOptions_prdMdl(checkbox)
	{
		var url; 
		if(comboGrid_defaultValue==""){
			url = '<%=path%>/product/prdBscInfo/initList.do?flag=quote'
		}else{
			url = '<%=path%>/product/prdBscInfo/initList.do?flag=quote&prdMdlsString='+comboGrid_defaultValue_prdMdl;
		}
	    var options = {
	    	usePager: false,
	        columns: [
	            { display: '产品型号', name: 'prdMdl', minWidth: 300 }
	        ],
	        switchPageSizeApplyComboBox: false,
	        url : url,
	        method: 'get',
	        dataAction: 'local',
	        pageSize: 10,
	        root:'rows',
	        record:'total',
	        usePagerOnLessPagesize: false,
	        cssClass: "SMALL_grid",
	        checkbox: checkbox,
	        frozen: false,
	        isSelected: function (rowdata) {
	            if (comboGrid_defaultValue_prdMdl == "") return false;
	            var defaultItems = comboGrid_defaultValue_prdMdl.split(";");
	            if(!isInit_setSearchComboVal_prdMdl) { //只在初始化时执行一次，在onAfterShowData后改变
	                for (var i = 0; i < defaultItems.length; i++) {
	                	if(rowdata[combo_Mng_prdMdl.options.valueField] == defaultItems[i]) return true;
	                }
	            }
	            return false;
	        },
	        onAfterShowData: function (currentData) {
	        	if(!isInit_setSearchComboVal_prdMdl) { //只在初始化时执行一次，在onAfterShowData后改变
	            	//combo_Mng_prdMdl.selectValue(comboGrid_defaultValue_prdMdl);
	            	combo_Mng_prdMdl.setInputValue(comboGrid_defaultValue_prdMdl, comboGrid_defaultText_prdMdl, true);
	                isInit_setSearchComboVal_prdMdl = true;
	        	}
	        	
	        }
	    };
	    return options;
	}
	$('#formSet1').ligerForm({
        validate : true
	});
	initData();
	
	 //省改变事件
	 $("#rgnPrCd_flag").change(function(){
		 if($("#rgnPrCd_flag").is(':checked')){
			 //设置市组件 市复选框取消选中  并且不可操作
			 liger.get("rgnCyCd").setDisabled(true);
			 liger.get("rgnCyCd_flag").setValue(false);
			 liger.get("rgnCyCd_flag").setDisabled(true);
		 }else{
			 liger.get("rgnCyCd").setEnabled();
			 liger.get("rgnCyCd_flag").setEnabled();
		 }
	 })
	 //市改变事件
	 $("#rgnCyCd_flag").change(function(){
		 if($("#rgnCyCd_flag").is(':checked')){
			 //设置市组件 市复选框取消选中  并且不可操作
			 liger.get("rgnPrCd").setDisabled(true);
			 liger.get("rgnPrCd_flag").setValue(false);
			 liger.get("rgnPrCd_flag").setDisabled(true);
		 }else{
			 liger.get("rgnPrCd").setEnabled();
			 liger.get("rgnPrCd_flag").setEnabled();
		 }
	 })
});

//选中省复选框事件
function checkProvince(){
	alert(11);
	if($("#rgnCyCd").checked){
		alert("市已经选中,省不可选");
	}
}
//选中市复选框事件
function checkCity(){
	if($("#rgnPrCd").checked){
		alert("省已经选中,市不可选");
	}
}
	
	function add(){
		var form = liger.get("formSet1");
		var data = form.getData();
		data["prpsCfgId"] = $("#prpsCfgId").val();
		//alert(JSON.stringify(data));
		var url = '<%=path%>/project/prjQuatPrpsAttr/add.do';
		var wait_dialog;
	    $.ajax({
			type: 'post',
			dataType:'json',
			data:data,
			url: url,
			beforeSend: function(){
		          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
		     },
			success:function(msg){
				 wait_dialog.close();
				 if(msg.success == 1){
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
				 }else{
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				 }
			}
		});
	}
	function initData(){
		var prpsCfgId = $("#prpsCfgId").val();
		if(!prpsCfgId){
			//chahgeItemStatus(true);
			return;
		}
    	var _url = '<%=path%>/project/prjQuatPrpsAttr/getById.do';
    	$.ajax({
    		type: 'get',
    		dataType:'json',
    		data:{prpsCfgId:prpsCfgId},
    		url: _url,
    		success:function(msg){
    			 if(msg.success == 1){
    				 setData(msg.data);//设置数据
    				 console.log(msg.data);
    			 }else{
    				 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
    			 }
    		}
    	});
   	}
		
	function setData(data){

		$("#friBaseOrgCd").ligerGetComboBoxManager().selectValue(data.friBaseOrgCd);
		$("#friBaseOrgCd").ligerGetComboBoxManager().updateStyle();
		if(data.friBaseOrgCd_flag=="1"){
			liger.get("friBaseOrgCd_flag").setValue(true);
		}

		$("#bizTypCd").ligerGetComboBoxManager().selectValue(data.bizTypCd);
		$("#bizTypCd").ligerGetComboBoxManager().updateStyle();
		if(data.bizTypCd_flag=="1"){
			liger.get("bizTypCd_flag").setValue(true);
		}
		
		$("#prjTypCd").ligerGetComboBoxManager().selectValue(data.prjTypCd);
		$("#prjTypCd").ligerGetComboBoxManager().updateStyle();
		if(data.prjTypCd_flag=="1"){
			liger.get("prjTypCd_flag").setValue(true);
		}
		
		$("#bizResCd").ligerGetComboBoxManager().selectValue(data.bizResCd);
		$("#bizResCd").ligerGetComboBoxManager().updateStyle();
		if(data.bizResCd_flag=="1"){
			liger.get("bizResCd_flag").setValue(true);
		}
		
		$("#splTypCd").ligerGetComboBoxManager().selectValue(data.splTypCd);
		$("#splTypCd").ligerGetComboBoxManager().updateStyle();
		if(data.splTypCd_flag=="1"){
			liger.get("splTypCd_flag").setValue(true);
		}
		
		$("#isGrpOrder").ligerGetComboBoxManager().selectValue(data.isGrpOrder);
		$("#isGrpOrder").ligerGetComboBoxManager().updateStyle();
		if(data.isGrpOrder_flag=="1"){
			liger.get("isGrpOrder_flag").setValue(true);
		}
		
		$("#brCd").ligerGetComboBoxManager().selectValue(data.brCd);
		$("#brCd").ligerGetComboBoxManager().updateStyle();
		if(data.brCd_flag=="1"){
			liger.get("brCd_flag").setValue(true);
		}
		
		$("#prdTypCd").ligerGetComboBoxManager().selectValue(data.prdTypCd);
		$("#prdTypCd").ligerGetComboBoxManager().updateStyle();
		if(data.prdTypCd_flag=="1"){
			liger.get("prdTypCd_flag").setValue(true);
		}
		$("#orgCd").ligerGetComboBoxManager().selectValue(data.orgCd);
		$("#orgCd").ligerGetComboBoxManager().updateStyle();
		if(data.orgCd_flag=="1"){
			liger.get("orgCd_flag").setValue(true);
		}
		
		$("#rgnPrCd").ligerGetComboBoxManager().selectValue(data.rgnPrCd);
		$("#rgnPrCd").ligerGetComboBoxManager().updateStyle();
		if(data.rgnPrCd_flag=="1"){
			liger.get("rgnPrCd_flag").setValue(true);
		}
		
		$("#rgnCyCd").ligerGetComboBoxManager().selectValue(data.rgnCyCd);
		$("#rgnCyCd").ligerGetComboBoxManager().updateStyle();
		if(data.rgnCyCd_flag=="1"){
			liger.get("rgnCyCd_flag").setValue(true);
		}
		
		if(data.splIds_flag=="1"){
			liger.get("splIds_flag").setValue(true);
		}
		
		if(data.prdMdls_flag=="1"){
			liger.get("prdMdls_flag").setValue(true);
		}
	}
</script>

</body>
</html>
